const app = getApp();
import grace from "../../../utils/grace.js";

grace.page({
  /**
   * 页面的初始数据
   */
  data: {
    student_id: 0,
    ferry_code1: '',
    ferry_code1_ref: '',
    ferry_code2: '',
    ferry_code2_ref: '',
    ferry_code3: '',
    ferry_code3_ref: ''
  },
  onLoad(e){
    this.$data.student_id = e.student_id;
  },
  onShow(e) {
    wx.showLoading({
      title: '加载中...',
    })

    // 查询孩子已绑定接送卡号
    let url = app.globalData.api + '/api/v1.0/student/ferry/' + this.$data.student_id;
    this.$http.get(url, { token: wx.getStorageSync('token') }).then((res) => {
      if (res.data.code == 0) {
        if(res.data.data['ferry_code1']){
          this.$data.ferry_code1 = res.data.data['ferry_code1'];
          this.$data.ferry_code1_ref = res.data.data['ferry_code1_ref'];
        }
        if(res.data.data['ferry_code2']){
          this.$data.ferry_code2 = res.data.data['ferry_code2'];
          this.$data.ferry_code2_ref = res.data.data['ferry_code2_ref'];
        }
        if(res.data.data['ferry_code3']){
          this.$data.ferry_code3 = res.data.data['ferry_code3'];
          this.$data.ferry_code3_ref = res.data.data['ferry_code3_ref'];
        }
      }
      wx.hideLoading();
    }).catch(err => {
      console.log(err);
    })
  },
  go_detail(e){
    wx.navigateTo({
      url: '/pages/home/guardian/detail_card?student_id=' + this.$data.student_id + '&card=' + e.currentTarget.dataset.card + '&code=' + e.currentTarget.dataset.code + '&ref=' + e.currentTarget.dataset.ref
    })
  },
  go_bind(e){
    wx.navigateTo({
      url: '/pages/home/guardian/bind_card?student_id=' + this.$data.student_id + '&card=' + e.currentTarget.dataset.card
    })
  }
})